<?php
namespace app\index\controller;

use think\Controller;
use think\Config;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

/**
 * Class: Qiniu 七牛云上传类
 * Author: Jason ZHENG <mingjun.zheng@zengduokeji.com>
 * Date: 2018-08-09
 */
class Qiniu extends Controller
{
	public function getToken()
	{
		$qiniuConfig = Config::get('qiniu');
  		// 初始化签权对象
		$auth = new Auth($qiniuConfig['accessKey'], $qiniuConfig['secretKey']);
		// 生成上传Token
		$token = $auth->uploadToken($qiniuConfig['bucket']);
		// 生成唯一的文件名key
		$key = md5(uniqid());
		return ReturnData::ok(['token' => $token, 'key' => $key]);
	}

	public function getTokenMerchant()
	{
		$qiniuConfig = Config::get('qiniu');
  		// 初始化签权对象
		$auth = new Auth($qiniuConfig['accessKey'], $qiniuConfig['secretKey']);
		// 生成上传Token
		$token = $auth->uploadToken($qiniuConfig['merchantBucket']);
		// 生成唯一的文件名key
		$key = md5(uniqid());
		return ReturnData::ok(['token' => $token, 'key' => $key]);
	}
}